@extends('layouts.admin_modal')

@section('content')
    <div class="box-body">
        <div class="form-group">
            <label for="input-name" class="col-sm-2 control-label">角色唯一名称</label>

            <div class="col-sm-10">
                {{--<dl class="permission-list">
                    <dt>
                        <label>
                            <input type="checkbox" value="" name="user-Character-0" id="user-Character-0" class="valid">
                            资讯管理</label>
                    </dt>
                    <dd>
                        <dl class="cl permission-list2">
                            <dt>
                                <label class="">
                                    <input type="checkbox" value="" name="user-Character-0-0" id="user-Character-0-0" class="valid">
                                    栏目管理</label>
                            </dt>
                            <dd>
                                <label class="">
                                    <input type="checkbox" value="" name="user-Character-0-0-0" id="user-Character-0-0-0">
                                    添加</label>
                                <label class="">
                                    <input type="checkbox" value="" name="user-Character-0-0-0" id="user-Character-0-0-1">
                                    修改</label>
                                <label class="">
                                    <input type="checkbox" value="" name="user-Character-0-0-0" id="user-Character-0-0-2">
                                    删除</label>
                                <label class="">
                                    <input type="checkbox" value="" name="user-Character-0-0-0" id="user-Character-0-0-3">
                                    查看</label>
                                <label class="">
                                    <input type="checkbox" value="" name="user-Character-0-0-0" id="user-Character-0-0-4">
                                    审核</label>
                                <label class="c-orange"><input type="checkbox" value="" name="user-Character-0-0-0" id="user-Character-0-0-5" class="valid"> 只能操作自己发布的</label>
                            </dd>
                        </dl>
                        <dl class="cl permission-list2">
                            <dt>
                                <label class="">
                                    <input type="checkbox" value="" name="user-Character-0-1" id="user-Character-0-1" class="valid">
                                    文章管理</label>
                            </dt>
                            <dd>
                                <label class="">
                                    <input type="checkbox" value="" name="user-Character-0-1-0" id="user-Character-0-1-0" class="valid">
                                    添加</label>
                                <label class="">
                                    <input type="checkbox" value="" name="user-Character-0-1-0" id="user-Character-0-1-1">
                                    修改</label>
                                <label class="">
                                    <input type="checkbox" value="" name="user-Character-0-1-0" id="user-Character-0-1-2">
                                    删除</label>
                                <label class="">
                                    <input type="checkbox" value="" name="user-Character-0-1-0" id="user-Character-0-1-3">
                                    查看</label>
                                <label class="">
                                    <input type="checkbox" value="" name="user-Character-0-1-0" id="user-Character-0-1-4">
                                    审核</label>
                                <label class="c-orange"><input type="checkbox" value="" name="user-Character-0-2-0" id="user-Character-0-2-5"> 只能操作自己发布的</label>
                            </dd>
                        </dl>
                    </dd>
                </dl>--}}

                @foreach($menuList as $key1=>$value1)
                <dl class="permission-list">
                    <dt>
                        <label class="">
                            <input type="checkbox" name="permissionList[]" value="{{ $value1['slug'] }}" @if(in_array($value1['slug'], $useList)) checked @endif id="user-Character-{{ $value1['id'] }}" class="valid">
                            {{ $value1['name'] }}
                        </label>
                    </dt>
                    @if(!empty($value1['_child']))
                    <dd>
                        @foreach($value1['_child'] as $key2=>$value2)
                        <dl class="cl permission-list2">
                            <dt>
                                <label class="">
                                    <input type="checkbox" name="permissionList[]" value="{{ $value2['slug'] }}" @if(in_array($value2['slug'], $useList)) checked @endif id="user-Character-{{ $value2['id'] }}" class="valid">
                                    {{ $value2['name'] }}
                                </label>
                            </dt>
                            @if(!empty($value2['_child']))
                            <dd>
                                @foreach($value2['_child'] as $key3=>$value3)
                                    <label class="">
                                        <input type="checkbox" name="permissionList[]" value="{{ $value3['slug'] }}" @if(in_array($value3['slug'], $useList)) checked @endif id="user-Character-{{ $value3['id'] }}" class="valid">
                                        {{ $value3['name'] }}
                                    </label>
                                @endforeach
                            </dd>
                            @endif
                        </dl>
                        @endforeach
                    </dd>
                    @endif
                </dl>
                @endforeach
            </div>
        </div>

    </div>

    <input type="hidden" name="role_id" value="{{ $roleId }}">
@endsection

@section('script')
    <style>
        /*.permission-list dl {border-left: 1px solid #ddd;padding-left:5px;}*/
        .permission-list {
            border: solid 1px #eee;
        }
        .permission-list > dt {
            background-color: #efefef;
            padding: 5px 10px;
        }
        .permission-list > dd {
            padding: 10px;
            padding-left: 30px;
        }
        .permission-list2 > dd {
            padding-left: 30px;
        }
    </style>
    <script>
        $(function () {
            $(".permission-list dt input:checkbox").click(function(){
                $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
            });


            $(".permission-list2 dd input:checkbox").click(function(){
                var l =$(this).parent().parent().find("input:checked").length;
                var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
                if($(this).prop("checked")){
                    $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
                    $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
                }
                else{
                    if(l==0){
                        $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
                    }
                    if(l2==0){
                        $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
                    }
                }
            });
        });


    </script>
@endsection
